const Router = require('koa-router')
const router = new Router()
const {
    getAllFrameList,
    getAllFrame2List,
    getAllFrameCount,
    getAllFrame2Count,
} = require('../controllers/index.js')


router.get('/getAllFrameList', async (ctx, next) => {
    const { page, size } = ctx.query
    
    
    try { 
        const res = await getAllFrameList({page, size})
        const total = await getAllFrameCount()
        

        if (res.length) {
            ctx.body = {
                code: 200,
                data: res,
                totalPage: Math.ceil(total[0].count / Number(size)),
                msg: '查询成功'
            }
        } else {
            ctx.body = {
                code: 200,
                data: [],
                totalPage: 0,
                msg: '暂无数据'
            }
        }
    } catch (error) {
        ctx.body = {
            code: 500,
            data: error,
            msg: '服务器异常'
        }
    }
})

router.get('/getAllFrame2List', async (ctx, next) => {
    const { page, size } = ctx.query
    try {
        const res = await getAllFrame2List({page, size})
        const total = await getAllFrame2Count()

        if (res.length) {
            ctx.body = {
                code: 200,
                data: res,
                totalPage: Math.ceil(total[0].count / Number(size)),
                msg: '查询成功'
            }
        } else {
            ctx.body = {
                code: 200,
                data: [],
                totalPage: 0,
                msg: '暂无数据'
            }
        }
    } catch (error) {
        ctx.body = {
            code: 500,
            data: error,
            msg: '服务器异常'
        }
    }
})

module.exports = router; 